﻿using Library.Common.Model;
using Library.Core.Application.IInfrastructure;
using Microsoft.Extensions.Logging;

namespace Library.Core.Application.EventHandler
{
    public class EventErrorHandler
    {
        private readonly ILogger<EventErrorHandler> logger;

        public EventErrorHandler(IIocContainer container)
        {
            logger = container.Resolve<ILogger<EventErrorHandler>>();
        }

        /// <summary>
        /// 事件订阅者的业务异常也打到日志系统里显示
        /// </summary>
        /// <param name="re"></param>
        /// <param name="tagName">功能模块名称</param>
        public void HandlerCustomError<T>(BaseApiResult<T> re, string tagName)
        {
            if (!re.Success)
            {
                logger.LogError($"{tagName},ErrorCode:{re.Code},ErrorMsg:{re.ErrMessage}");
            }
        }

    }
}
